﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour {

    public float Factor;

    private float startTime;
    private bool enableInput;
    private Rigidbody rigidbody;
    private Vector3 jumpDirction;
    

    private void Start()
    {
        rigidbody = gameObject.GetComponent<Rigidbody>();
        rigidbody.centerOfMass = Vector3.zero;
        enableInput = true;
    }

    private void Update()
    {
        if (enableInput)
        {
            // jumpDirction = gameObject.transform.rotation;
            // jumpDirction = Quaternion.Euler(gameObject.transform.rotation.x, gameObject.transform.rotation.y, gameObject.transform.rotation.z).;
            jumpDirction = transform.forward;
            if (Input.GetMouseButtonDown(0))
            {
                startTime = Time.time;
            }
            if (Input.GetMouseButtonUp(0))
            {
                float clickTimeSpan = Time.time - startTime;
                OnJump(clickTimeSpan);
                Debug.Log("跳起来");
            }
            if (Input.GetMouseButton(0))
            {
                Debug.Log("点击了鼠标");
               // enableInput = false;
            }
        }
        else
        {

        }
        
    }

    private void OnJump(float timeSpan)
    {
        rigidbody.AddForce(jumpDirction* timeSpan * Factor, ForceMode.Impulse);
       // rigidbody.MovePosition(new Vector3(0, 0, 5f) );
       // gameObject.transform.Translate();
    }

    private void OnCollisionExit(Collision collision)
    {
        //enableInput = false;
    }

}
